Questions
2 of 25
1How do you define a TypeORM entity and register it in a NestJS feature module?
2How do you handle TypeORM migrations in a NestJS project?
3How do you run a transaction with Prisma in NestJS?
4How do you perform CRUD operations and add query methods to a Mongoose model in NestJS?
5How do you use Prisma with multiple databases in a single NestJS application?
6What is the difference between find(), findOne(), findOneOrFail(), and the Query Builder in TypeORM?
7What are the two main ways to run a database transaction in TypeORM with NestJS?
8How do you handle Prisma migrations in a CI/CD pipeline?
9How do you add schema middleware (hooks) and instance methods in NestJS Mongoose?
10How do you mock a repository in a NestJS unit test?
11How do you seed a database in a NestJS application?
12How do you implement a Unit of Work pattern to group database operations across repositories in NestJS?
13How do you implement optimistic locking with TypeORM to prevent lost updates in NestJS?
14How do you integrate Prisma into a NestJS application?
15How do you implement soft deletes in NestJS with TypeORM?
16How do you implement multi-tenancy with a shared database in NestJS TypeORM?
17How do you set up TypeORM in a NestJS application?
18How do you implement a custom TypeORM repository in NestJS?
19How do you propagate a TypeORM transaction across multiple services in NestJS?
20What are Prisma middleware and how do you use them for audit logging in NestJS?
21How do you set up Mongoose in a NestJS application and define a schema?
22How do you handle Mongoose transactions for multi-document atomic operations in NestJS?
23What is the repository pattern and why use it in NestJS?
24How do you handle database connection pooling and health checks in NestJS?
25How do you implement database read replicas in NestJS for read/write splitting with TypeORM?
02 / 25

How do you handle TypeORM migrations in a NestJS project?

Create a separate datasource.ts file for the TypeORM CLI that does not depend on the NestJS app module. Generate migrations with migration:generate, apply with migration:run, and roll back with migration:revert. Never use synchronize: true in production — use migrations exclusively.

Separate datasource and migration workflow
Migration workflow best practices:
  1. 1

    Never use synchronize: true in production — it can drop columns and tables destructively.

  2. 2

    Keep a separate datasource.ts for the TypeORM CLI so it works independently of the NestJS app module.

  3. 3

    Always implement down() — rollbacks are critical for safe deployments and hotfixes.

  4. 4

    Commit all migration files to version control — they are the source of truth for schema history.

  5. 5

    Use migrationsRun: true in the NestJS TypeORM config to auto-apply pending migrations on startup.

Difficulty: 5/10
Topics: migration generation, migration execution, migration strategy

Scenario Questions

0-2 years experience
  1. 1

    You need to add a new column to an existing User entity. Walk me through the steps you’d take to create and apply a TypeORM migration in a NestJS project.

  2. 2

    If you run npm run migration:run and it reports 'No pending migrations', but you know you added a new entity field, what could be causing that and how would you fix it?

2-5 years experience
  1. 1

    During a feature rollout, a migration fails halfway on production because of a NOT NULL constraint. How would you diagnose and resolve the issue without causing downtime?

  2. 2

    Explain why you might choose to write a migration manually instead of letting TypeORM generate it automatically, and give an example where the generated migration would be problematic.

5-8 years experience
  1. 1

    Our service runs in a zero‑downtime deployment pipeline and serves traffic from multiple instances. How would you design a migration strategy using TypeORM in NestJS to ensure schema changes are applied safely across all instances?

  2. 2

    We have a multi‑tenant database where each tenant has its own schema. How would you manage TypeORM migrations to handle schema versioning per tenant while keeping the codebase maintainable?

8+ years experience
  1. 1

    Across several microservices that share a common database, how would you coordinate TypeORM migrations to avoid version drift and ensure consistent schema evolution across teams?

  2. 2

    Describe a long‑term migration governance process you’d put in place for a large organization using NestJS and TypeORM, covering CI/CD integration, rollback procedures, and documentation.

Follow-up Questions

  • What challenges have you faced when a migration caused data loss, and how did you mitigate them?
  • How do you ensure migrations are idempotent and safe to run multiple times?
  • Can you talk about how you version‑control migration files alongside application code?